require(['jquery', 'cookie', 'app', "lay"], function ($) {
    require(['vue'], function (Vue) {
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                where: {},
                userInfo: {},
                info: {
                    name: "",
                    secretKey: ""
                }
            }
            , created: function () {
                this.userInfo = JSON.parse(localStorage.getItem("userInfo"));
                this.loadPage();
            }
            , methods: {
                loadPage: function () {
                    load();
                    var toolbar = [];
                    toolbar.push({
                        "clas": "",
                        "eve": "ADD",
                        "tit": "新增商户",
                        "fnc": function (data) {
                            dic.openAdd();
                        }
                    });
                    toolbar.push({
                        "clas": "",
                        "eve": "UPDATE",
                        "tit": "更改状态",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            const re = playPut("/v1/api/tenant/" + data[0].uuid + "/state", "", "");
                            alr(re["msg"])
                        }
                    });
                    var tool = [];
                    bspVIEW($("#authoritiesTable"), "/v1/api/tenant/all", [
                        {type: 'radio',minWidth: 50, width: 80},
                        {type: 'numbers'},
                        {field: 'uuid', title: '商户Id', minWidth: 50, width: 200},
                        {field: 'code', title: '商户编码', minWidth: 50, width: 200},
                        {field: 'name', title: '商户名称', minWidth: 50, width: 120},
                        {field: 'secretKey', title: '秘钥', minWidth: 50, width: 150},
                        {field: 'money', title: '已充值金额', minWidth: 50, width: 120},
                        {field: 'modifiedTime', title: '更新时间', minWidth: 50, width: 120},
                        {field: 'createTime', title: '创建时间', minWidth: 50, width: 120},
                        {
                            templet: function (d) {
                                if (d.status) {
                                    return "<p style=\"background-color: green;color: white\">启用 </p>";
                                } else {
                                    return "<p style=\"background-color: red;color: white\">禁用</p>";
                                }
                            },
                            align: 'center',
                            width: 120,
                            title: '账号状态'
                            , minWidth: 120
                        },
                    ], {common: this.where}, toolbar, tool, function (res, curr, count) {

                    });
                },
                seachs: function () {
                    this.where = fromName($(".el-form"));
                    this.loadPage();
                },
                refer: function () {

                },
                openAdd: function () {
                    alrYN($("#add"), function () {
                        loading();
                        const re = playPost("v1/api/tenant/save", dic.info, "");
                        reloading();
                        alr(re["msg"]);
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000);
                    }, function () {

                    }, function () {

                    }, "请输入信息", 1, ["600px", "350px"]);
                }
            }
        });
    })
});